package com.ks.user.controller;


import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.user.controller.dto.RoleRequest;
import com.ks.user.service.IPowerUserRoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 用户角色表 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-11-30
 */
@RestController
@RequestMapping("/powerUserRole")
public class PowerUserRoleController extends _ControllerBase {

    @Autowired
    private IPowerUserRoleService powerUserRoleService;

    @PostMapping("/getUserRoleList")
    @ApiOperation(value = "获取员工的角色列表", notes = "获取员工的角色列表")
    public Object getUserRoleList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> userRoleList = powerUserRoleService.getUserRoleList(getContext(), searchCriteriaBase);
        return Result.success(userRoleList);
    }

    @PostMapping("/addUserRole")
    @ApiOperation(value = "添加员工的角色", notes = "添加员工的角色")
    public Object addUserRole(@RequestBody RoleRequest roleRequest) {
        int i = powerUserRoleService.addRoleList(getContext(), roleRequest.getResurceIds(), roleRequest.getUserId());
        return Result.success(i);
    }

    @PostMapping("/moveUserRoleList")
    @ApiOperation(value = "移除员工的角色", notes = "移除员工的角色")
    public Object moveUserRoleList(@RequestBody RoleRequest roleRequest) {
        int i = powerUserRoleService.moveRoleList(getContext(), roleRequest.getResurceIds(), roleRequest.getUserId());
        return Result.success(i);
    }

}

